import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
// import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import ColorTagToggleList from '#/components/tag/src/color-tag-toggle-list.vue';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const columns: VxeGridProps['columns'] = [
  // {
  //   type: 'checkbox',
  //   width: 60,
  // },
  {
    dragSort: true,
    title: '拖拽排序',
    width: 90,
  },
  {
    type: 'seq',
    width: 60,
  },
  {
    field: 'name',
    title: '选项名称',
    align: 'left',
    minWidth: 200,
    slots: { default: 'name' },
  },
  {
    title: '标签类型',
    field: 'labelType',
    width: 150,
    slots: {
      default: ({ row }) => {
        return renderDict(
          row.labelType,
          DictEnum.QUESTIONNAIRE_QUESTION_OPTION_TYPE,
          true,
        );
      },
    },
  },
  {
    title: '关联标签',
    field: 'labels',
    minWidth: 200,
    slots: {
      default: ({ row }) => {
        return <ColorTagToggleList labels={row.labels} />;
      },
    },
  },
  {
    title: '备注',
    field: 'remark',
    showOverflow: true,
    visible: false,
  },
  {
    title: '状态',
    field: 'status',
    slots: { default: 'status' },
    width: 80,
  },
  // {
  //   title: '关联题目',
  //   field: 'secondaryQuestionName',
  //   width: 160,
  // },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 160,
  },
];

export const questionOptionSchema: FormSchemaGetter = () => [
  {
    label: 'ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '题目id',
    fieldName: 'questionId',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '题目选项名称',
    fieldName: 'name',
    component: 'Input',
    rules: 'required',
  },
  {
    component: 'Select',
    componentProps(model) {
      return {
        options: getDictOptions(
          DictEnum.QUESTIONNAIRE_QUESTION_OPTION_TYPE,
          true,
        ),
        onChange: () => {
          model.labelIds = [];
        },
      };
    },
    fieldName: 'labelType',
    label: '标签类型',
  },
  {
    label: '企业标签',
    fieldName: 'labelIds',
    component: 'CompanyTagSelect',
    defaultValue: [],
    dependencies: {
      if: (values) => values.labelType === 1,
      triggerFields: ['labelType'],
    },
  },
  {
    label: '个人标签',
    fieldName: 'labelIds',
    component: 'PersonalTagSelect',
    defaultValue: [],
    dependencies: {
      if: (values) => values.labelType === 2,
      triggerFields: ['labelType'],
    },
  },
  {
    component: 'InputNumber',
    fieldName: 'sort',
    help: '排序, 数字越小越靠前',
    label: '显示排序',
    defaultValue: 0,
    rules: 'required',
  },
  {
    component: 'QuestionSelect',
    fieldName: 'secondaryQuestionId',
    label: '关联题目',
    help: '当用户选择此选项时，才显示被关联的题目。\n注：仅单选题可关联题目。',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
      optionType: 'button',
    },
    defaultValue: '0',
    fieldName: 'status',
    label: '状态',
    rules: 'selectRequired',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
  },
];
